﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using C = System.Console;
using Edu.Console;
using System.Collections;
using Edu.Console.Patterns;
using Site.Domain.Core.Abstract;
using Site.Domain.Core.Concrete;

namespace Edu.Console
{
    class A1 { public static int Value = 11;  public virtual void DoSmth() { C.WriteLine("A1"+Value.ToString()); } }
    class A2 : A1 { public override void DoSmth() { C.WriteLine("A2"+A2.Value.ToString()); } }
    class A3 : A2 { public virtual new void DoSmth() { C.WriteLine("A3"); } }
    class A4 : A3 { public override void DoSmth() { C.WriteLine("A4"); } }
    class Mine : A4 { public override void DoSmth() { C.WriteLine("Mine"); } }

    interface IPrint
    {
        void Print();
        void Setup();
        void GetDocument();
    }

    public sealed class CoolPrinter : IPrint
    {
        public void Print()
        {
            C.WriteLine("Cool print");
        }

        public void Setup()
        {
            C.WriteLine("Cool setup");
        }

        public void GetDocument()
        {
            C.WriteLine("Cool document");
        }
    }

    public class MyPrinter:IPrint
    {
        private CoolPrinter printer = new CoolPrinter();


        public void Print()
        {
            C.WriteLine("Vasya cool!");
            printer.Print();
        }

        public void Setup()
        {
            printer.Setup();
        }

        public void GetDocument()
        {
            printer.GetDocument();
        }
    }

    //------------------------------
    public class MyCollection:IEnumerable
    {
        public MyCollection()
        {
            storage[0] = "0";
            storage[1] = "1";
            storage[2] = "2";
            storage[3] = "3";
            storage[4] = "4";

        }
        private string[] storage = new string[5];

        public IEnumerator GetEnumerator()
        {
            return new MyCollection.MyCollectionEnumerator(this);
            //return (storage as IEnumerable).GetEnumerator();
        }

        private class MyCollectionEnumerator : IEnumerator
        {
            int currentIndex = 0;
            private MyCollection owner;

            public MyCollectionEnumerator(MyCollection owner)
            {
                this.owner = owner;
            }
            public object Current
            {
                get { return owner.storage[currentIndex++]; }
            }

            public bool MoveNext()
            {
                if (currentIndex > owner.storage.Length-1) return false;                
                return true;
            }

            public void Reset()
            {
                currentIndex = 0;
            }
        }
    }
    
    class Classes
    {
        public static void Lesson()
        {
            IPage page = Site.Domain.Core.Factory.CreatePage("Page 1", "page 1");
            C.WriteLine("{0} {1}", page.Name, page.GetType().Name);
            /*var card = new PokerCard();
            card = Factory.CreatePokerCard();*/
            /*var s1 = Singleton.Instance;
            var s2 = Singleton.Instance;
            if (s1 == s2) C.WriteLine("Yra");
            s1 = Singleton.Instance;
            Singleton.ResetInstance();
            s2 = Singleton.Instance;
            if (s1 == s2) C.WriteLine("Yra 2");
            */
            /*var collection = new MyCollection();            
            foreach (var element in collection) C.WriteLine(element.ToString());
            A1 a = new A2();
            a.DoSmth();
            */
            /*IPrint printer = new MyPrinter();
            printer.Print();
            printer = new CoolPrinter();
            printer.Print();
             */
            /*var card1 = new AtlasCard(CardRank.K, malicious: true);
            var card2 = new PokerCard(CardRank.A);
            //card1.Draw();
            //card2.Draw();
            var cards = new Card[] { card1, card2 };
            foreach (var card in cards) card.Draw();
            //C.WriteLine(String.Format("{0}:{1}", card1.Suit, card1.Rank));
            //1
            C.WriteLine(String.Format("{0}:{1}", card2.Suit, card2.Rank));
             */

        }
    }
}
